/**
 * 
 */
package game;

/**
 * @author Jean-Baptiste BORIC
 *
 */
public class Unit {
	private UnitType type;
	private Player player;
	
	private int x;
	private int y;
	private int health;
	private boolean isActive;
	
	/**
	 * @param type
	 * @param player
	 * @param x
	 * @param y
	 */
	public Unit(UnitType type, Player player, int x, int y) {
		super();
		this.setType(type);
		this.setPlayer(player);
		this.setCoordinates(x, y);
		this.setHealth(10);
		this.setActive(true);
	}

	/**
	 * @return Unit type
	 */
	public UnitType getType() {
		return type;
	}
	
	/**
	 * @param type Unit ype
	 */
	public void setType(UnitType type) {
		this.type = type;
	}
	
	/**
	 * @return Unit's player
	 */
	public Player getPlayer() {
		return player;
	}
	
	/**
	 * @param player Unit's player
	 */
	public void setPlayer(Player player) {
		this.player = player;
	}
	
	/**
	 * @return X position
	 */
	public int getX() {
		return x;
	}
	
	/**
	 * @return Y position
	 */
	public int getY() {
		return y;
	}
	
	/**
	 * @param x X position
	 * @param y Y position
	 */
	public void setCoordinates(int x, int y) {
		if(x < 0 || y < 0) {
			throw new IllegalArgumentException("Invalid coordinates");
		}
		this.x = x;
		this.y = y;
	}
	
	/**
	 * @return the health
	 */
	public int getHealth() {
		return health;
	}
	
	/**
	 * @param health the health to set
	 */
	public void setHealth(int health) {
		if(health < 0 || health > 10) {
			//throw new IllegalArgumentException("Health not between 0 and 10");
		}
		this.health = health;
	}
	
	/**
	 * @return the isActive
	 */
	public boolean isActive() {
		return isActive;
	}
	
	/**
	 * @param isActive the isActive to set
	 */
	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	@Override
	public String toString() {
		String str = type.getName() + "\t" + player.getID() + "\t" + x + "\t" + y + "\t" + health + "\t" + isActive;
		
		// Fill unused data
		str += "\t99\t99\t0";
		
		return str;
	}
}
